<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目属性：</label>
                        <div class="layui-input-block">
                            <select id="business" name="business" lay-filter="business">
                                <option value="">请选择</option>
                                <option value="1">自营</option>
                                <option value="2">联营</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目状态：</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">

</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('投标保证金一览');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_lan_bond_tou_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xiala_zhan_one_zuo('state', res.data.state, res.data.is_state);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field:'name',title:'项目名称',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../engin/show.php?id='+d.id+'\')">'+d.name+'</span>';
                    }}
                ,{field: 'number', title: '项目编号'}
                ,{field: 'business_name', title: '项目属性'}
                ,{field: 'state_name', title: '项目状态'}
                ,{field: 'feitype_name', title: '费用项'}
                ,{field:'bondshoufee',title:'保证金收取金额(元)',totalRow: true,align:'right',event: 'bond_shou',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.bondshoufee)+'</span>';
                    }}
                ,{field:'bondjiaofee',title:'保证金缴纳金额(元)',totalRow: true,align:'right',event: 'bond_jiao',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.bondjiaofee)+'</span>';
                    }}
                ,{field:'bondtuifee',title:'保证金退回金额(元)',totalRow: true,align:'right',event: 'bond_tui',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.bondtuifee)+'</span>';
                    }}
                ,{field:'bondtuikoufee',title:'扣款金额(元)',totalRow: true,align:'right',event: 'bond_tui',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.bondtuikoufee)+'</span>';
                    }}
                ,{field:'bondfanfee',title:'保证金返还金额(元)',totalRow: true,align:'right',event: 'bond_fan',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.bondfanfee)+'</span>';
                    }}
                ,{field:'bonddaituifee',title:'待退金额(元)',totalRow: true,align:'right',templet: function(d){return parseFormatNum(d.bonddaituifee);}}
                ,{field:'bonddaifanfee',title:'待返金额(元)',totalRow: true,align:'right',templet: function(d){return parseFormatNum(d.bonddaifanfee);}}
                ,{field: 'chanid_name', title: '项目所属单位'}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'bond_shou'){
                openNavPage('查看保证金收取信息','bond_shou/index.php?status=1&enginid='+data.id+'&feitype='+data.feitype);
            }
            if(obj.event === 'bond_jiao'){
                openNavPage('查看保证金缴纳信息','bond_jiao/index.php?status=1&enginid='+data.id+'&feitype='+data.feitype);
            }
            if(obj.event === 'bond_tui'){
                openNavPage('查看保证金退回信息','bond_tui/index.php?status=1&enginid='+data.id+'&feitype='+data.feitype);
            }
            if(obj.event === 'bond_fan'){
                openNavPage('查看保证金返还信息','bond_fan/index.php?status=1&enginid='+data.id+'&feitype='+data.feitype);
            }
        });

        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('../engin/show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('../engin/add.php?close=1&business=1');
    }
    function auth_but_func_add_flow(){
        openPageEdit('../engin/flow_add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('../engin/edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_engin_del, {id:trData.id});
    }

    function auth_but_func_kaijun(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        if(checkStatus.length != 1){
            facade.error(buttitle + "：请选择操作数据");return false;
        }

        var checkData = checkStatus[0];
        if(checkData.isturn != 1 || checkData.status != 1){
            facade.error(buttitle + "：选择的数据正在申请中，无法操作");return false;
        }
        openPageEdit('../engin/kaijun.php?close=1&id='+checkData.id);
    }
    function auth_but_func_manage(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        if(checkStatus.length != 1){
            facade.error(buttitle + "：请选择操作数据");return false;
        }

        var checkData = checkStatus[0];
        if(checkData.isturn != 1 || checkData.status != 1){
            facade.error(buttitle + "：选择的数据正在申请中，无法操作");return false;
        }
        openPageEdit('../engin/manage.php?close=1&id='+checkData.id);
    }


</script>
</body>
</html>
